﻿using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using Abp.ObjectMapping;
using CPPProject.CppModel;
using CPPProject.CppServices.Dto;
using Microsoft.EntityFrameworkCore;
using OplugAbpProject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;


namespace CPPProject.CppServices
{
    public class T_Biz_LocationAppService : AsyncCrudAppService<T_Biz_Location, T_Biz_LocationDto, Guid, PagedResultRequestDto, UpdateT_Biz_LocationDto, UpdateT_Biz_LocationDto>, IT_Biz_LocationAppService
    {
        private readonly IObjectMapper _objectMapper;
        public T_Biz_LocationAppService(IRepository<T_Biz_Location, Guid> repository, IObjectMapper objectMapper) : base(repository)
        {
            _objectMapper = objectMapper;
        }
        #region 站点信息
        /// <summary>
        /// 站点信息
        /// </summary>
        /// <param name="nCompanyID">公司ID</param>
        /// <param name="cName">站点名称</param>
        /// <param name="skipCount"></param>
        /// <param name="maxResultCount"></param>
        /// <returns></returns>
        public async Task<PagedResultDto<T_Biz_LocationDto>> GetList(string nCompanyID,  string cName = "", int skipCount = 0, int maxResultCount = 100)
        {
            PagedResultDto<T_Biz_LocationDto> resultDto = new PagedResultDto<T_Biz_LocationDto>();
            List<T_Biz_Location> lists = new List<T_Biz_Location>();
            Expression<Func<T_Biz_Location, bool>> expr = o => o.NCompanyID == nCompanyID;
            if (!string.IsNullOrEmpty(cName))//站点名称
            {
                expr = expr.ExpressionAnd(o => o.CName == cName);
            }
            lists = await Repository.GetAll().Where(expr).ToListAsync();
            var dtos = lists.Skip(skipCount).Take(maxResultCount).ToList();
            resultDto.Items = _objectMapper.Map<List<T_Biz_LocationDto>>(dtos);
            resultDto.TotalCount = lists.Count;
            return resultDto;
        }
        #endregion
    }
}
